﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DICE_GS;

public class SummonSceneManager : MonoBehaviour
{
    // 메뉴 라벨
    public UILabel m_PremiumBtnLabel;
    public UILabel m_NormalBtnLabel;
    public UILabel m_CardLabel;
    public UILabel m_TicketLabel;
    public UILabel m_PointLabel;

    // 벨류 라벨
    public UILabel m_CrrCard;
    public UILabel m_MaxCard;
    public UILabel m_SummonTicket;
    public UILabel m_SummonPoint;

    public GameObject m_PremiumButton;
    public GameObject m_NormalButton;

	// Use this for initialization
	void Awake () {
        //m_PremiumBtnLabel.text = CStringTableManager.Instance.GetItemById(2303);
        //m_NormalBtnLabel.text = CStringTableManager.Instance.GetItemById(2304);
        //m_CardLabel.text = CStringTableManager.Instance.GetItemById(1878);
        //m_TicketLabel.text = CStringTableManager.Instance.GetItemById(2306);
        //m_PointLabel.text = CStringTableManager.Instance.GetItemById(2305);

        ButtonDisable(m_PremiumButton, false);
        ButtonDisable(m_NormalButton, false);

        m_CrrCard.text = "";
        m_MaxCard.text = "";
        m_SummonTicket.text = "";
        m_SummonPoint.text = "";

        LoadingWindow.window.ShowShortLoading();
        RestAPI.singleton.RefreshUserData(CallBackOfRefreshUserData);       
	}

    void CallBackOfRefreshUserData(Hashtable returnData)
    {
        LoadingWindow.window.HideLoading();
        RestAPI.singleton.GetMyUnitList(CallBackOfRefreshMyUnitList); 
    }

    void CallBackOfRefreshMyUnitList(Hashtable returnData)
    {
        m_CrrCard.text = MyInfo.Instance.MyUnitsList.Count.ToString();
        m_MaxCard.text = MyInfo.Instance.currentInvenCount.ToString();
        m_SummonTicket.text = MyInfo.Instance.gachaTicket.ToString();
        m_SummonPoint.text = MyInfo.Instance.gachaPoint.ToString();

        int NeedDiamond = CGSettingDataManager.Instance.GetValue("default_cash_gacha_require_diamond");
        int NeedPoint = CGSettingDataManager.Instance.GetValue("default_normal_gacha_require_point");
        int NeedTicket = CGSettingDataManager.Instance.GetValue("default_cash_gacha_require_ticket");


        Debug.LogError("heeso --- NeedDiamond = " + NeedDiamond);
        Debug.LogError("heeso --- NeedPoint = " + NeedPoint);
        Debug.LogError("heeso --- NeedTicket = " + NeedTicket);


        ButtonDisable(m_PremiumButton, true);
        ButtonDisable(m_NormalButton, true);


        if (MyInfo.Instance.MyUnitsList.Count >= MyInfo.Instance.currentInvenCount)  //인벤이 꽉차면
        {
            ButtonDisable(m_PremiumButton, false);
            ButtonDisable(m_NormalButton, false);
        }
        else
        {
            if (MyInfo.Instance.gachaPoint < NeedPoint)  //노멀 뽑기 안됨
            {
                ButtonDisable(m_NormalButton, false);
            }

            if (MyInfo.Instance.gachaTicket < NeedTicket && MyInfo.Instance.diamond < NeedDiamond)  //프리미엄 뽑기 안됨
            {
                ButtonDisable(m_PremiumButton, false);
            }
        }
    }


    void ButtonDisable(GameObject obj, bool isActive)
    {
        obj.collider.enabled = isActive;

        MultiplySpriteColor sc = obj.GetComponent<MultiplySpriteColor>();
        if (sc == null)
            sc = obj.AddComponent<MultiplySpriteColor>();

        if (isActive)
            sc.enabled = !isActive;
        else
        {
            sc.MulEndColor = Color.gray;
            sc.Apply(true);
        }
    }
}
